package com.simple.jdbc.core.sqlSession;

import com.simple.jdbc.core.config.XMLConfigBuilder;
import com.simple.jdbc.core.pojo.Configuration;
import org.dom4j.DocumentException;

import java.io.InputStream;

public class SqlSessionFactoryBuilder {

    /**
     * 解析配置文件
     * 创建工厂对象
     * @return
     */
    public SqlSessionFactory build(InputStream inputStream) throws DocumentException {

        //解析           XMLConfigBuilder 专门接卸核心配置文件的解析类
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parse(inputStream);

        //创建sqlSessionFactory工厂对象
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);

        return defaultSqlSessionFactory;
    }

}
